package com.ruijiang.controller.vm_service;

import com.ruijiang.controller.ApiPrefix;
import com.ruijiang.dto.insert.PolicyInsertDto;
import com.ruijiang.dto.page.PageBaseDto;
import com.ruijiang.dto.page.PagePolicyDto;
import com.ruijiang.entity.Policy;
import com.ruijiang.result.PageResult;
import com.ruijiang.service.VmService.PolicyService;
import com.ruijiang.vo.policy.PolicyVMVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(ApiPrefix.VM_SERVICE+"/policy")
@Slf4j
public class PolicyController {

    @Autowired
    private PolicyService policyService;


    @GetMapping("/search")
    public PageResult getList(PagePolicyDto dto){
        log.info("查询策略列表 : {}",dto);
        PageResult pageResult = policyService.getList(dto);
        return pageResult;
    }


    @DeleteMapping("/{policyId}")
    public Boolean deletePolicyById(@PathVariable String policyId){
        log.info("删除策略 : {}",policyId);
        policyService.deletePolicyById(policyId);
        return true;
    }

    /**
     * 新增策略
     * @return
     */
    @PostMapping
   public Boolean insertPolicy(PolicyInsertDto dto){
        log.info("新增策略 : {}",dto);
        policyService.insertPolicy(dto);
        return true;
   }

    /**
     * 查询售货机策略
     * @return
     */
   @GetMapping("/vmPolicy/{innerCode}")
   public PolicyVMVO getPolicyByInnerCode(@PathVariable String innerCode){
       log.info("查询售货机策略 : {}",innerCode);
       return policyService.getPolicyByInnerCode(innerCode);
   }

    /**
     * 根据策略返回售货机
     * @return
     */
    @GetMapping("/vmList/{policyId}")
   public PageResult getVMByPolicy(@PathVariable String policyId, PageBaseDto dto){
        log.info("根据策略返回售货机 : {}",policyId);
        return policyService.getVMByPolicy(policyId,dto);
   }

    /**
     * 修改策略
     * @param policyId
     * @return
     */
   @PutMapping("/{policyId}")
   public Boolean updatePolicyById(@PathVariable String policyId,@RequestBody PolicyInsertDto dto){
        log.info("修改策略 : {},{}",policyId,dto);
        policyService.updatePolicyById(policyId,dto);
        return true;
   }


}
